package com.push.web.spider;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.push.common.utils.httpclient.HttpClientResult;
import com.push.common.utils.httpclient.HttpClientUtil;
import com.push.web.domain.BizToutiaoNews;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import us.codecraft.webmagic.selector.Html;
import us.codecraft.webmagic.selector.Selectable;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class TouTiaoNewsSpider {
    private static final int TIMEOUT = 10000;

    public static void main(String[] args){
        HashMap params = new HashMap();
        params.put("showcid","56261");
        params.put("page","1");
        HttpClientResult newsResult = HttpClientUtil.doGet("http://interface.sina.cn/wap_api/layout_col.d.json", params, false);

        JSONObject resultObj = JSONObject.parseObject(newsResult.getContent());
        JSONArray newsArray = resultObj.getJSONObject("result").getJSONObject("data").getJSONArray("list");
        for (int i = 0; i< newsArray.size(); i++){
            BizToutiaoNews bizToutiaoNews = new BizToutiaoNews();
            bizToutiaoNews.setId(newsArray.getJSONObject(i).getString("news_id"));
            bizToutiaoNews.setTitle(newsArray.getJSONObject(i).getString("title"));
            bizToutiaoNews.setDescription(newsArray.getJSONObject(i).getString("summary"));
            bizToutiaoNews.setPicUrl(newsArray.getJSONObject(i).getString("pc_url"));
            bizToutiaoNews.setCtime(newsArray.getJSONObject(i).getDate("cdateTime"));
            bizToutiaoNews.setSource(newsArray.getJSONObject(i).getString("source"));
            bizToutiaoNews.setUrl(newsArray.getJSONObject(i).getString("URL"));
            System.out.println(bizToutiaoNews.toString());
        }
    }

}
